package UIFree
{
	import flash.filters.BevelFilter;
	import flash.filters.BitmapFilter;
	import flash.filters.DropShadowFilter;
	
	public class uif_FXComponent extends uif_ecomponent {
		protected var _bevel: Number;
		protected var _bevelUpdateFunc: Function;
		
		protected var _shadow: Number;
		protected var _shadowUpdateFunc: Function;
		
		public function uif_FXComponent(parent:uif_component, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, styleClass:String='') {
			super(parent, ax, ay, awidth, aheight, styleClass);
			_bevel = 0;
		}
		
		public function FCFilter(filter: Class): BitmapFilter {
			var result: BitmapFilter;
			filters.forEach(function(elem: BitmapFilter, index:int, arr: Array): void {
				if (elem is filter) result = elem;
			});
			if (!result) {
				result = new filter();
			}
			return result;
		}
		
		public function set bevelUpdateFunc(a_func: Function): void {
			_bevelUpdateFunc = a_func;
		}
		
		public function set shadowUpdateFunc(a_func: Function): void {
			_shadowUpdateFunc = a_func;
		}
		
		protected function blevelUpdate(): void {
			if (_bevelUpdateFunc != null) {
				applyFilter(_bevelUpdateFunc(FCFilter(BevelFilter), _bevel));
			}
		}
		
		protected function shadowUpdate(): void {
			if (_shadowUpdateFunc != null) {
				applyFilter(_shadowUpdateFunc(FCFilter(DropShadowFilter), _shadow));
			}
		}
		
		public function get FXbevel(): Number {
			return _bevel;
		}
		
		public function set FXbevel(a_value: Number): void {
			_bevel = a_value;
			blevelUpdate();
		}

		public function get FXshadow(): Number {
			return _shadow;
		}
		
		public function set FXshadow(a_value: Number): void {
			_shadow = a_value;
			shadowUpdate();
		}
	}
}